<template>
  <div class="app-container">
    <!-- 工具条 -->
    <div>
      <el-button type="danger" size="mini" @click="addCategory()">添加</el-button>
    </div>
    <!-- 表格 -->
    <el-table
      :data="list"
      border
      fit
      highlight-current-row>

      <el-table-column
        label="序号"
        width="70"
        align="center">
        <template slot-scope="scope">
          {{ (page - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>

      <el-table-column prop="name" label="类型名称" width="300" align="center"/>
      <el-table-column prop="gmtCreate" label="添加时间" width="160" align="center"/>
      <el-table-column label="操作" width="300" align="center">
        <!--
        TODO 没写完的部分
        -->
        <template slot-scope="scope">
          <router-link :to="'/article/categoryEdit/'+scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit"></el-button>
          </router-link>
          <el-button type="danger" size="mini" icon="el-icon-delete" @click="removeDataById(scope.row.id)"></el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-pagination
      :current-page="page"
      :page-size="limit"
      :total="total"
      style="padding: 30px 0; text-align: center;"
      layout="total, prev, pager, next, jumper"
      @current-change="getList"
    />

  </div>
</template>

<script>
  import article from '../../../api/article/article'

  export default {
    data(){
      return{
        list: null, //查询之后给接口返回的数据装的集合
        page: 1, //当前页
        limit: 5, //每页显示记录数
        total: 0, //总记录数
        articleCategory:{},//文章分类
      }
    },
    created() {
      this.getList();
    },
    methods:{
      addCategory(){
        this.$router.push({ path: 'save'})
      },
      //文章列表的方法
      getList(page=1){
        this.page = page;
        article.getArticleCategoryListPage(this.page,this.limit)
          .then(resp=>{
            //response接口返回的数据
            // console.log(resp);
            this.list = resp.data.rows;
            this.total = resp.data.total;
          })//请求成功
          .catch(error=>{
          })//请求失败
      },
      //清空方法
      resetData() {
        //表单输入项数据清空
        this.articleQuery = {};
        //查询所有课程数据
        this.getList();
      },
      //删除文章类型的方法
      removeDataById(id) {
        this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => { // promise
          // 点击确定，远程调用ajax
          return article.delArticleCategory(id)
        }).then((response) => {
          this.getList(this.page)
          if (response.success) {
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
          }
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      },
    }
  }
</script>

<style scoped>

</style>
